package com.example.kafka.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.example.kafka.service.KafkaService;

/**
 * @author jiyupeng
 */
@RestController
@RequestMapping("/kafka")
public class KafkaController {
	
	@Autowired
	private KafkaService kafkaService;
	
	@GetMapping("message")
	public String sendMessage(@RequestParam("message") String message) {
		kafkaService.sendMessageInAsyncWay(message);
		return "success";
	}
	
	@GetMapping("messageInTransaction")
	public String sendMessageInTransaction(@RequestParam("message") String message) throws Exception {
		kafkaService.sendMessageInTransactionAnno(message);
		return "success";
	}
	
	@PostMapping("topic")
	public String createTopic(@RequestParam("topic") String topic) {
		kafkaService.createTopic(topic);
		return "success";
	}
}
